home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gnat1792.zip / gnat179b / t-adainc / s-secsta.ads < prev    next >
Text File  |  1994-05-19  |  4KB  |  80 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT COMPILER COMPONENTS                         --
  4. --                                                                          --
  5. --               S Y S T E M . S E C O N D A R Y _ S T A C K                --
  6. --                                                                          --
  7. --                                 S p e c                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.7 $                              --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. --
  22. --                                                                          --
  23. ------------------------------------------------------------------------------
  24.  
  25. package System.Secondary_Stack is
  26.  
  27.    --  The Secondary Stack is used to allocate anonymous objects created for
  28.    --  storing intermediate result of functions returning unconstrained objects
  29.  
  30.    --  The basic use of this stack is the following:
  31.  
  32.    --    * before executing such a function (when the call doesn't appear in a
  33.    --      return statement), the stack is marked
  34.  
  35.    --    * after execution, and copy of the intermediate result, the stack is
  36.    --      poped until the mark is reached.
  37.  
  38.    --    * during execution, the function allocates its returned value in the
  39.    --      secondary stack (as well as other function calls in the return
  40.    --      statement)
  41.  
  42.    type Mark_Id is private;
  43.    --  Type used to mark the stack.
  44.  
  45.    procedure SS_Init (Stk : out Address; Size : Natural);
  46.    --  Initialize the secondary stack with a main stack of the given Size.
  47.    --  All further allocations which do not overflow the main stack will not
  48.    --  generate dynamic (de)allocation calls. If the main Stack is overflowed
  49.    --  a linked list of dynamically allocated chunks of memory takes place.
  50.    --  Note: the reason that Stk is passed is that SS_Init is called before
  51.    --  the proper interface is established to obtain the address of the
  52.    --  stack using System.Task_Specific_Data.Get_Sec_Stack_Addr.
  53.  
  54.    procedure SS_Free (Stk : Address);
  55.    --  Release the memory allocated for the Secondary Stack
  56.  
  57.    function SS_Mark return Mark_Id;
  58.    --  Return the Mark corresponding to the current state of the stack
  59.  
  60.    procedure SS_Release (M : Mark_Id);
  61.    --  Restore the state of the stack corresponding to the mark M. Frees
  62.    --  all storage allocated by SS_Allocate since the SS_Mark operation
  63.    --  that returned the value M.
  64.  
  65.    function SS_Allocate (Size : Natural) return Address;
  66.    --  Allocate a chunk of memory of the given Size (in Storage_Units)
  67.  
  68.    generic
  69.       with procedure Put_Line (S : String);
  70.    procedure SS_Info;
  71.    --  Debugging procedure used to print out secondary Stack allocation
  72.    --  information. This procedure is generic in order to avoid a direct
  73.    --  dependance on a particular IO package.
  74.  
  75. private
  76.  
  77.    type Mark_Id is new Natural;
  78.  
  79. end System.Secondary_Stack;
  80.